package cn.bdqn.hospital.service.impl;

import cn.bdqn.hospital.dao.OrderAllDao;
import cn.bdqn.hospital.dao.impl.OrderAllDaoImp;
import cn.bdqn.hospital.entity.OrderAll;
import cn.bdqn.hospital.service.OrderAllService;
import cn.bdqn.hospital.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 订单总表业务层实现类
 */
public class OrderAllServiceImpl implements OrderAllService {

    OrderAllDao orderAllDao = new OrderAllDaoImp();

    /**
     * 添加订单总表
     *
     * @param orderAll
     * @return
     * @throws SQLException
     */
    @Override
    public boolean add(OrderAll orderAll) throws SQLException {
        Connection connection = null;
        int num = 0;
        try{
            connection = DruidUtils.getConnection();
            connection.setAutoCommit(false);// 关闭事物控制
            num = orderAllDao.add(orderAll);
            if(num == 1){// 新增订单总表成功
                connection.commit();// 提交
            }
        } catch (Exception e){
            connection.rollback();// 不提交
            e.printStackTrace();
        } finally {
            DruidUtils.close();
        }
        return (num == 1);
    }
}
